package com.weslide.weslideapp.parser;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.weslide.weslideapp.pojo.ao.AdverImgListAO;
import com.weslide.weslideapp.pojo.ao.AdverimgsAO;

public class GetAdverImgsParser {
	private AdverImgListAO adverimgsListAO = new AdverImgListAO();

	public void parser(String jsonString) throws JSONException {
		JSONArray jsonArray = new JSONArray(jsonString);
		JSONObject statusJsonObject = jsonArray.getJSONObject(0);
		adverimgsListAO.setStatus(statusJsonObject.getString("status"));
		if (adverimgsListAO.getStatus().equals("1")) {
			for (int i = 1; i < jsonArray.length(); i++) {
				AdverimgsAO adverimgsAO = new AdverimgsAO();
				JSONObject dataJsonObject = jsonArray.getJSONObject(i);
				adverimgsAO.setGoodId(dataJsonObject.getString("good_id"));
				adverimgsAO.setAdverImgUrls(dataJsonObject
						.getString("adver_imgurls"));

				adverimgsAO
						.setWebSiteId(dataJsonObject.getString("website_id"));

				adverimgsAO.setUrl(dataJsonObject.getString("url"));
				adverimgsAO.setName(dataJsonObject.getString("name"));
				adverimgsListAO.addImg(adverimgsAO);
			}

		}
	}

	public AdverImgListAO getData() {
		return this.adverimgsListAO;
	}
}
